package com.scau402.system1.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.scau402.system1.domain.vo.WmsCheckBoundOrderDetailVO;
import com.scau402.system1.domain.factory.WmsCheckBoundOrderFactory;
import com.scau402.system1.domain.po.WmsCheckboundOrderDetailPO;
import com.scau402.system1.mapper.IWmsCheckboundOrderDetailMapper;
import com.scau402.system1.repository.IWmsCheckDetailRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 盘点详情单Repository实现类
 * @since 2024/2/3
 */
@Repository
@Slf4j
public class WmsCheckDetailRepositoryImpl implements IWmsCheckDetailRepository {
    @Autowired
    private IWmsCheckboundOrderDetailMapper checkDetailMapper;
    @Autowired
    private WmsCheckBoundOrderFactory wmsCheckBoundOrderFactory;

    @Override
    public void save(WmsCheckboundOrderDetailPO detailPO) {
        checkDetailMapper.insert(detailPO);
    }

    /**
     * 根据盘点单（不是详情）id修改
     * @param orderDetail 详情对象
     * @param checkOrderId 盘点单id
     */
    @Override
    public void updateByCheckOrderId(WmsCheckboundOrderDetailPO orderDetail, Long checkOrderId) {
        checkDetailMapper.update(orderDetail,new QueryWrapper<WmsCheckboundOrderDetailPO>().eq("check_order_id", checkOrderId));
    }

    /**
     * 通过盘点单id获取详情
     * @param checkOrderId 盘点单id
     * @return
     */
    @Override
    public WmsCheckboundOrderDetailPO findDetailByCheckOrderId(Long checkOrderId) {
        return checkDetailMapper.selectOne(new QueryWrapper<WmsCheckboundOrderDetailPO>().eq("check_order_id", checkOrderId));
    }

    /**
     * 通过盘点单号获取盘点单详情
     * @param checkOrderId 盘点单号
     * @return
     */
    @Override
    public WmsCheckBoundOrderDetailVO findOneByCheckOrderId(Long checkOrderId) {
        return checkDetailMapper.selectOneByCheckOrderId(checkOrderId);
    }
}
